﻿#!/usr/bin/env python3

from string import Template

def main():
    '''
string.Template -
实现了$identifier形式的模板替换. 经常被用作解决i18n问题.
替换符是$identifer或${identifier}形式, 匹配identifer的key, 替换为相应的value.
identifier是case-insensitive的. ${id}形式适用于其后紧跟非替换内容时,例如${identifier}s, if $identifier="egg", the res = eggs

    '''
    print(main.__doc__)

    d=dict(name='Tom')
    d2={'name':'Tom', 'question':"How are you?"}
    s = Template("Hi, $name. $question")

    t = s.substitute(name="Tom", question="How are you?")
    print(t)

    t = s.substitute(d2)
    print(t)

    s = Template("Hi, ${name}. ${question}")
    t = s.substitute(name="Tom", question="How are you?")
    print(t)






if __name__=='__main__':
    main()


